package com.wt.controller;

import com.alibaba.fastjson.JSONObject;
import com.wt.entity.Order;
import com.wt.service.OrderService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/FixOrderServlet")
public class FixOrderServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码
        response.setContentType("application/json;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        //获取参数
        Integer orderId = Integer.valueOf(request.getParameter("orderId"));
        Integer stater = Integer.valueOf(request.getParameter("stater"));
        OrderService orderService = new OrderService();
        try {
            Boolean res = orderService.updateOrderStater(orderId,stater);
            PrintWriter out = response.getWriter();
            String err = null;
            if (res){
                err = "{\"data\":true}";
            }else {
                err = "{\"data\":false}";
            }
            out.write(err);
            out.flush();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            PrintWriter out = response.getWriter();
            String err = "{\"data\":\"error\"}";
            out.write(err);
            out.flush();
        }
    }
}
